//
// Created by 吴锐 on 2022/2/26.
//

#include "iostream"

using namespace std;

class Calculator {
public:
    int m_Num1;
    int m_Num2;

    int getResult(string oper) {
        if (oper == "+") {
            return m_Num1 + m_Num2;
        } else if (oper == "-") {
            return m_Num1 - m_Num2;
        } else if (oper == "*") {
            return m_Num1 * m_Num2;
        } else {
            return m_Num1 / m_Num2;
        }
    }
};

void test01() {
    Calculator c;
    c.m_Num1 = 10;
    c.m_Num2 = 20;

    cout << c.m_Num1 << " + " << c.m_Num2 << " = " << c.getResult("+") << endl;
    cout << c.m_Num1 << " - " << c.m_Num2 << " = " << c.getResult("-") << endl;
    cout << c.m_Num1 << " * " << c.m_Num2 << " = " << c.getResult("*") << endl;
    cout << c.m_Num1 << " / " << c.m_Num2 << " = " << c.getResult("/") << endl;
}

class AbstractCalculator {
public:
    int a;
    int b;

    virtual int getResult() {
        return 0;
    }
};

class AddCalculator : public AbstractCalculator {
public:
    int getResult() {
        return a + b;
    }
};

class SubCalculator : public AbstractCalculator {
public:
    int getResult() {
        return a - b;
    }
};

class MulCalculator : public AbstractCalculator {
public:
    int getResult() {
        return a * b;
    }
};

void test02() {
    AbstractCalculator* abc = new AddCalculator;
    abc->a = 10;
    abc->b = 20;
    cout << abc->a << " + " << abc->b << " = " << abc->getResult() << endl;
    delete abc;
}

int main() {
//    test01();
    test02();
    return 0;
}